



set more off
mat drop _all




use "$path_data/data/temp/main_reg_data_psc.dta", clear




foreach i in DT_per_min DT_score DT_time {
replace `i'_pre = . if wrongDT == 1
gen `i'_pre_miss = `i'_pre
gen `i'_dum_miss = 0
replace `i'_dum_miss = 1 if `i'_pre == .
replace `i'_pre_miss = 0 if `i'_pre == .
}

gen pts_pre_miss = ptsbl_overall_score
gen pts_dum_miss = 0
replace pts_dum_miss = 1 if ptsbl_overall_score == .
replace pts_pre_miss = 0 if ptsbl_overall_score == .






foreach i in rosen cpcs {
gen `i'_pre_miss = `i'_bl
gen `i'_dum_miss = 0
replace `i'_dum_miss = 1 if `i'_bl == .
replace `i'_pre_miss = 0 if `i'_bl == .
}

*********************
*********************
******* Table 2
*********************
*********************







**************************
*** LNGOVA Specifications
**************************


foreach i in DT_per_min DT_score DT_time  {

	 regress `i'_post treatment treatment_longer `i'_pre_miss `i'_dum_miss, cluster(school_no)

	matrix LNG1_`i'_post_temp = r(table)
	matrix LNG1_`i'_post_r2 = e(r2)
	matrix LNG1_`i'_post_obs = e(N)

	 cgmwildboot_2 `i'_post treatment treatment_longer `i'_pre_miss `i'_dum_miss , cluster(school_no) bootcluster(school_no) null(0 0 . .) reps(999) seed(1)
	matrix LNG1_`i'_post_temp_p = e(Pvals)

	
	foreach s in be se pv rpv wpv {
		matrix LNG1_`i'_post_`s' = J(7,1,.)
	}

	foreach j in 1 2 3 4 5 6 7 {
		* beta
		matrix LNG1_`i'_post_be[`j',1] = LNG1_`i'_post_temp[1,`j']
		* standard error
		matrix LNG1_`i'_post_se[`j',1] = LNG1_`i'_post_temp[2,`j']
		* p value
		matrix LNG1_`i'_post_pv[`j',1] = LNG1_`i'_post_temp[4,`j']
		matrix LNG1_`i'_post_wpv[`j',1] = LNG1_`i'_post_temp_p[`j',1]
	}

*	cgmwildboot `i' treatment wrongDT cheating wrongTshort wrongTlong dum_grade, ///
*	cluster(school_no) bootcluster(school_no) null(0 . . . . . ) reps(999) seed(1)


	
}

foreach i in ptsel_overall_score {

	 regress `i' treatment treatment_longer pts_pre_miss pts_dum_miss, cluster(school_no)

	matrix LNG1_`i'_temp = r(table)
	matrix LNG1_`i'_r2 = e(r2)
	matrix LNG1_`i'_obs = e(N)

	 cgmwildboot_2 `i' treatment treatment_longer pts_pre_miss pts_dum_miss, cluster(school_no) bootcluster(school_no) null(0 0 . .) reps(999) seed(1)
	matrix LNG1_`i'_temp_p = e(Pvals)

	
	foreach s in be se pv rpv wpv {
		matrix LNG1_`i'_`s' = J(7,1,.)
	}

	foreach j in 1 2 3 4 5 6 7 {
		* beta
		matrix LNG1_`i'_be[`j',1] = LNG1_`i'_temp[1,`j']
		* standard error
		matrix LNG1_`i'_se[`j',1] = LNG1_`i'_temp[2,`j']
		* p value
		matrix LNG1_`i'_pv[`j',1] = LNG1_`i'_temp[4,`j']
		matrix LNG1_`i'_wpv[`j',1] = LNG1_`i'_temp_p[`j',1]
	}

*	cgmwildboot `i' treatment wrongDT cheating wrongTshort wrongTlong dum_grade, ///
*	cluster(school_no) bootcluster(school_no) null(0 . . . . . ) reps(999) seed(1)


	
}




foreach i in rosen cpcs {

	 regress `i'_el treatment treatment_longer `i'_pre_miss `i'_dum_miss, cluster(school_no)

	matrix LNG1_`i'_el_temp = r(table)
	matrix LNG1_`i'_el_r2 = e(r2)
	matrix LNG1_`i'_el_obs = e(N)

	 cgmwildboot_2 `i'_el treatment treatment_longer `i'_pre_miss `i'_dum_miss, cluster(school_no) bootcluster(school_no) null(0 0 . .) reps(999) seed(1)
	matrix LNG1_`i'_el_temp_p = e(Pvals)

	
	foreach s in be se pv rpv wpv {
		matrix LNG1_`i'_el_`s' = J(7,1,.)
	}

	foreach j in 1 2 3 4 5 6 7 {
		* beta
		matrix LNG1_`i'_el_be[`j',1] = LNG1_`i'_el_temp[1,`j']
		* standard error
		matrix LNG1_`i'_el_se[`j',1] = LNG1_`i'_el_temp[2,`j']
		* p value
		matrix LNG1_`i'_el_pv[`j',1] = LNG1_`i'_el_temp[4,`j']
		matrix LNG1_`i'_el_wpv[`j',1] = LNG1_`i'_el_temp_p[`j',1]
	}

*	cgmwildboot `i' treatment wrongDT cheating wrongTshort wrongTlong dum_grade, ///
*	cluster(school_no) bootcluster(school_no) null(0 . . . . . ) reps(999) seed(1)


	
}



foreach s in be se pv rpv r2 obs wpv {
	matrix LNG1_`s' = LNG1_DT_per_min_post_`s', LNG1_DT_score_post_`s', ///
	LNG1_DT_time_post_`s', LNG1_ptsel_overall_score_`s', ///
	LNG1_rosen_el_`s', LNG1_cpcs_el_`s'
}

































forvalues n = 1/1 {
forvalues item = 1/5 {
		forvalues scale = 1/6 {
		if LNG`n'_wpv[`item', `scale']<=0.01 {
			local star`n'_`item'`scale' %3s "***"
		}
		else if (LNG`n'_wpv[`item', `scale']>0.01) & (LNG`n'_wpv[`item', `scale']<=0.05) {
			local star`n'_`item'`scale' %2s "**"
		}
		else if (LNG`n'_wpv[`item', `scale']>0.05) & (LNG`n'_wpv[`item', `scale']<=0.10) {
			local star`n'_`item'`scale' %1s "*"
		}
		else {
			local star`n'_`item'`scale'  ""
		}
	} // forvalues `scale' loop

}  // forvalues `item' loop


} // forvalues `n' loop






forvalues n = 1/1 {
forvalues item = 1/5 {
		forvalues scale = 1/6 {
		if LNG`n'_pv[`item', `scale']<=0.01 {
			local nstar`n'_`item'`scale' %3s "***"
		}
		else if (LNG`n'_pv[`item', `scale']>0.01) & (LNG`n'_pv[`item', `scale']<=0.05) {
			local nstar`n'_`item'`scale' %2s "**"
		}
		else if (LNG`n'_pv[`item', `scale']>0.05) & (LNG`n'_pv[`item', `scale']<=0.10) {
			local nstar`n'_`item'`scale' %1s "*"
		}
		else {
			local nstar`n'_`item'`scale'  ""
		}
	} // forvalues `scale' loop

}  // forvalues `item' loop


} // forvalues `n' loop




tempname hh
file open `hh' using "$pardir/table4.tex", write replace
file write `hh' "" _newline
file write `hh' "% Date: `c(current_date)'" _newline
file write `hh' "% Time: `c(current_time)'" _newline
file write `hh' "" _newline





file write `hh' "\begin{table}[t!]\footnotesize" _newline
file write `hh' "  \centering" _newline
file write `hh' "  \caption{Impact of Kumon on Students’ Learning Outcomes: Estimates Controlling for Longer Kumon Sessions}" _newline
file write `hh' "\label{tab:DID_longer}" _newline
file write `hh' "\scalebox{0.75}{" _newline
file write `hh' "\begin{threeparttable}" _newline
file write `hh' "\begin{tabular}{lcccccc}\toprule" _newline
file write `hh' "Dependent Variable & DT Score per min\textsuperscript{a} & DT Score & DT Time   & PTSII-C Score\textsuperscript{b} & RSES Index\textsuperscript{c}     & CPCS Index\textsuperscript{c} \\" _newline
file write `hh' " & (1) & (2) & (3) & (4) & (5) & (6)   \\\midrule\midrule" _newline
file write `hh' "Treatment           &  " %04.3f (LNG1_be[1, 1]) `star1_11' "  &  " %04.3f (LNG1_be[1, 2]) `star1_12' "  &  " %04.3f (LNG1_be[1, 3]) `star1_13' "  &  " %04.3f (LNG1_be[1, 4]) `star1_14' "  &  " %04.3f (LNG1_be[1, 5]) `star1_15' "  &  " %04.3f (LNG1_be[1, 6]) `star1_16' "  \\" _newline
file write `hh' "                    & (" %04.3f (LNG1_se[1, 1]) ") & (" %04.3f (LNG1_se[1, 2]) ") & (" %04.3f (LNG1_se[1, 3]) ") & (" %04.3f (LNG1_se[1, 4]) ") & (" %04.3f (LNG1_se[1, 5]) ") & (" %04.3f (LNG1_se[1, 6]) ") \\" _newline

file write `hh' "Treatment $\times$ Longer Session &  " %04.3f (LNG1_be[2, 1]) `star1_21' "  &  " %04.3f (LNG1_be[2, 2]) `star1_22' "  &  " %04.3f (LNG1_be[2, 3]) `star1_23' "  &  " %04.3f (LNG1_be[2, 4]) `star1_24' "  &  " %04.3f (LNG1_be[2, 5]) `star1_25' "  &  " %04.3f (LNG1_be[2, 6]) `star1_26' "  \\" _newline
file write `hh' "                    & (" %04.3f (LNG1_se[2, 1]) ") & (" %04.3f (LNG1_se[2, 2]) ") & (" %04.3f (LNG1_se[2, 3]) ") & (" %04.3f (LNG1_se[2, 4]) ") & (" %04.3f (LNG1_se[2, 5]) ") & (" %04.3f (LNG1_se[2, 6]) ") \\" _newline


file write `hh' "Baseline Outcome            &  " %04.3f (LNG1_be[3, 1]) `nstar1_31' "  &  " %04.3f (LNG1_be[3, 2]) `nstar1_32' "  &  " %04.3f (LNG1_be[3, 3]) `nstar1_33' "  &  " %04.3f (LNG1_be[3, 4]) `nstar1_34' "  &  " %04.3f (LNG1_be[3, 5]) `nstar1_35' "  &  " %04.3f (LNG1_be[3, 6]) `nstar1_36' "  \\" _newline
file write `hh' "                    & (" %04.3f (LNG1_se[3, 1]) ") & (" %04.3f (LNG1_se[3, 2]) ") & (" %04.3f (LNG1_se[3, 3]) ") & (" %04.3f (LNG1_se[3, 4]) ") & (" %04.3f (LNG1_se[3, 5]) ") & (" %04.3f (LNG1_se[3, 6]) ") \\" _newline

file write `hh' "constant           &  " %04.3f (LNG1_be[5, 1]) `nstar1_51' "  &  " %04.3f (LNG1_be[5, 2]) `nstar1_52' "  &  " %04.3f (LNG1_be[5, 3]) `nstar1_53' "  &  " %04.3f (LNG1_be[5, 4]) `nstar1_54' "  &  " %04.3f (LNG1_be[5, 5]) `nstar1_55' "  &  " %04.3f (LNG1_be[5, 6]) `nstar1_56' "  \\" _newline
file write `hh' "                    & (" %04.3f (LNG1_se[5, 1]) ") & (" %04.3f (LNG1_se[5, 2]) ") & (" %04.3f (LNG1_se[5, 3]) ") & (" %04.3f (LNG1_se[5, 4]) ") & (" %04.3f (LNG1_se[5, 5]) ") & (" %04.3f (LNG1_se[5, 6]) ") \\" _newline
file write `hh' "                    &                                 &                                 &                                 &                                 &                                 &                         \\\midrule" _newline
file write `hh' "Num of Obs.         &  " (LNG1_obs[1, 1]) " &  " (LNG1_obs[1, 2]) " &  " (LNG1_obs[1, 3]) " &  " (LNG1_obs[1, 4]) " &  " (LNG1_obs[1, 5]) " &  " (LNG1_obs[1, 6]) " \\" _newline
file write `hh' "R-squared           &  " %04.3f (LNG1_r2[1, 1]) "  &  " %04.3f (LNG1_r2[1, 2]) "  &  " %04.3f (LNG1_r2[1, 3]) "  &  " %04.3f (LNG1_r2[1, 4]) "  &  " %04.3f (LNG1_r2[1, 5]) "  &  " %04.3f (LNG1_r2[1, 6]) "  \\" _newline
file write `hh' "                    &                  &          &           &               &         &          \\" _newline
file write `hh' "\midrule" _newline


*file write `hh' " \multicolumn{7}{l}{p-values on the Treatment Dummy} \\" _newline

file write `hh' "p-value (individual hypothesis testing) &  " %04.3f (LNG1_pv[1, 1]) "  &  " %04.3f (LNG1_pv[1, 2]) "  &  " %04.3f (LNG1_pv[1, 3]) "  &  " %04.3f (LNG1_pv[1, 4]) "  &  " %04.3f (LNG1_pv[1, 5]) "  &  " %04.3f (LNG1_pv[1, 6]) "  \\" _newline
file write `hh' "p-value (individual hypothesis testing, wildbootstrap) &  " %04.3f (LNG1_wpv[1, 1]) "  &  " %04.3f (LNG1_wpv[1, 2]) "  &  " %04.3f (LNG1_wpv[1, 3]) "  &  " %04.3f (LNG1_wpv[1, 4]) "  &  " %04.3f (LNG1_wpv[1, 5]) "  &  " %04.3f (LNG1_wpv[1, 6]) "  \\" _newline
*file write `hh' "p-value (Romano-Wolf stepdown p-values) &  " %04.3f (LNG1_rpv[1, 1]) "  &  " %04.3f (LNG1_rpv[1, 2]) "  &  " %04.3f (LNG1_rpv[1, 3]) "  &  " %04.3f (LNG1_rpv[1, 4]) "  &  " %04.3f (LNG1_rpv[1, 5]) "  &  " %04.3f (LNG1_rpv[1, 6]) "  \\" _newline
file write `hh' "                    &                  &          &           &               &         &          \\\midrule" _newline

*file write `hh' " \multicolumn{7}{l}{p-values on the Treatment Dummy * Longer Session Dummy: SEPARATE REGRESSION FROM ABOVE} \\" _newline

*file write `hh' "p-value (individual hypothesis testing) &  " %04.3f (LNG1_pv[2, 1]) "  &  " %04.3f (LNG1_pv[2, 2]) "  &  " %04.3f (LNG1_pv[2, 3]) "  &  " %04.3f (LNG1_pv[2, 4]) "  &  " %04.3f (LNG1_pv[2, 5]) "  &  " %04.3f (LNG1_pv[2, 6]) "  \\" _newline
*file write `hh' "p-value (individual hypothesis testing, wildbootstrap) &  " %04.3f (LNG1_wpv[2, 1]) "  &  " %04.3f (LNG1_wpv[2, 2]) "  &  " %04.3f (LNG1_wpv[2, 3]) "  &  " %04.3f (LNG1_wpv[2, 4]) "  &  " %04.3f (LNG1_wpv[2, 5]) "  &  " %04.3f (LNG1_wpv[2, 6]) "  \\" _newline
*file write `hh' "p-value (Romano-Wolf stepdown p-values) &  " %04.3f (LNG1_rpv[2, 1]) "  &  " %04.3f (LNG1_rpv[2, 2]) "  &  " %04.3f (LNG1_rpv[2, 3]) "  &  " %04.3f (LNG1_rpv[2, 4]) "  &  " %04.3f (LNG1_rpv[2, 5]) "  &  " %04.3f (LNG1_rpv[2, 6]) "  \\" _newline
file write `hh' "                    &                  &          &           &               &         &          \\\midrule" _newline





file write `hh' "\end{tabular}" _newline
file write `hh' "\end{threeparttable}" _newline
file write `hh' "}" _newline
file write `hh' "\label{tab:addlabel}%" _newline
file write `hh' "\end{table}" _newline









